from contextlib import closing

class CloseDemo:
    def __init__(self) -> None:
        self.acquire()

    def acquire(self):
        print("lock data")
    
    def free(self):
        print("unlock data")

    def close(self):
        self.free()

with closing(CloseDemo()):
    print("use data")